<?php

namespace app\admin\controller\com;

use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;
use think\facade\Db;

/**
 * @ControllerAnnotation(title="com_amounts")
 */
class Amounts extends AdminController
{

    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\admin\model\ComAmounts();
        
    }
    public function show(){
        $order = ['id'=>1,'is_o'=>1,'t_id'=>1,'price'=>100];

        if($order['is_o']==1){
            $a = $this->commission($order);
            print_r($a);
        }
    }

    public function commission($order)
    {
        $t_id = $order['t_id'];

        $data = Db::table('ea_group_master')->where('id',$t_id)->find();

        $datas = Db::table('ea_group_master_grade')->where('id',$data['grade_id'])->find();

        $commission = $order['price']*($datas['reward_ratio']*0.01);

        $s = Db::table('ea_com_amounts')->insert([
            'reg_id'=>$t_id,
            'order_id'=>$order['id'],
            'commission'=>$commission,
            'created_at'=>date("Y-m-d H:i:s")
        ]);

        return $s;
    }
}